package main

import (
	"os"
	"xinanjiang-go/app"
	"xinanjiang-go/utils"
)

func main() {
	runPath, _ := os.Getwd()
	params := utils.ReadParamsFile(runPath)

	var watershed app.Watershed
	watershed.SetState(&params)
	watershed.Calculate(&params)

	var evapotranspiration app.Evapotranspiration
	evapotranspiration.SetParams(&params)

	state := make([]app.State, watershed.SubWatershedNum)

	for i := 0; i < len(state); i++ {
		state[i].SetDT(params.Time)
		state[i].SetParams()
	}

	var runoff app.Runoff
	runoff.SetParams(&params)

	var source app.Source
	source.SetParams(&params)

	var confluence app.Confluence
	confluence.SetParams(&params)

	var muskingum app.Muskingum
	muskingum.SetParams(&params)

	timeScale := params.RainfallRecordsRows     // 时间尺度长度
	subWatershedNum := params.MAreaSubWatershed // 子流域数量

	m_Q := make([]float64, timeScale)

	for i := 0; i < timeScale; i++ {
		state[0].MQ = 0.0
		for j := 0; j < len(subWatershedNum); j++ {

			state[j].SetInput(i, j, watershed)

			// 蒸散发计算
			evapotranspiration.SetState(&state[j])
			evapotranspiration.Calculate()
			evapotranspiration.UpdateState(&state[j])

			// 产流计算
			runoff.SetState(&state[j])
			runoff.Calculate()
			runoff.UpdateState(&state[j])

			//分水源计算
			source.SetState(&state[j])
			source.Calculate()
			source.UpdateState(&state[j])

			// 产汇流计算
			confluence.SetState(&state[j])
			confluence.Calculate()
			confluence.UpdateState(&state[j])

			// 马斯根京
			muskingum.SetState(&state[j])
			muskingum.Calculate()
			muskingum.UpdateState(&state[j])

			//单元出口流量累加
			state[0].MQ += state[j].O2
		}
		m_Q[i] = state[0].MQ
	}
	print("N")
}
